﻿using System;
using System.Linq;
using System.Windows.Forms;

namespace SolutionFactory.UI
{
    public partial class TemplateInputView : Form, ITemplateInputView
    {
        public TemplateInputView()
        {
            InitializeComponent();
        }

        #region ITemplateInputView Members

        public Action CancelClicked { get; set; }
        public Action AcceptClicked { get; set; }

        public string TemplateName
        {
            get { return txtTemplateName.Text; }
            set { txtTemplateName.Text = value; }
        }

        public string Description
        {
            get { return txtDescription.Text; }
            set { txtDescription.Text = value; }
        }

        public string Category
        {
            get { return cboProjectType.Text; }
            set { cboProjectType.Text = value; }
        }

        public string SubCategory
        {
            get { return cboProjectSubType.Text; }
            set { cboProjectSubType.Text = value; }
        }

        public string OutputDirectory
        {
            get { return txtDestinationPath.Text; }
            set { txtDestinationPath.Text = value; }
        }

        public string RunOnCompletion
        {
            get { return cboCommandToRun.SelectedIndex > 0 ? cboCommandToRun.Text : ""; }
            set { }
        }

        public bool IncludeParentDirectory
        {
            get { return chkIncludeParentDirectory.Checked; }
            set { chkIncludeParentDirectory.Checked = value; }
        }

        public void ShowDialog()
        {
            base.ShowDialog();
        }

        public void SetCommandsToRun(string[] commands)
        {
            cboCommandToRun.DataSource = new[] {"Do Not Run a Command"}.Union(commands).ToArray();
        }

        #endregion

        private void btnExport_Click(object sender, EventArgs e)
        {
            AcceptClicked.Invoke();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            CancelClicked.Invoke();
        }
    }
}